#include "skcircle.h"
#include "skpoint.h"
#include <QPainter>
SkCircle::SkCircle(int const& id, SkPoint *p1, SkPoint *p2,QGraphicsItem * parent):
        SkLine(id,p1,p2,parent)
{
    setZValue(-2);
    setFlag(ItemIsSelectable);
    sourcePoint()->addLine(this);
    destPoint()->addLine(this);
    adjust();

}
QRectF SkCircle::boundingRect() const{
    if (!source || !dest)
        return QRectF();

    QLineF line(sourcePn, destPn);
    qreal ads = destPoint()->radius();
    QPointF p1(sourcePn.x()-line.length()-ads,sourcePn.y()-line.length()-ads);
    return QRectF(p1, QSizeF(2*line.length()+2*ads,2*line.length()+2*ads))
            .normalized();

}
void SkCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
	Q_UNUSED(option);
	Q_UNUSED(widget);
    if (!source || !dest)
        return;

    QLineF line(sourcePn, destPn);
    if (qFuzzyCompare(line.length(), qreal(0.)))
        return;


    painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
    painter->drawEllipse(sourcePn,line.length(),line.length());
    painter->setPen(QPen(Qt::blue,1,Qt::DotLine));
    painter->drawLine(line);

}
